home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / SDKs / Now Utilities Plug Ins 6.0 / API Stuff / Now Tabs Plug Ins ƒ / Sample Dialog Plug In ƒ / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-07  |  2.6 KB  |  133 lines  |  [TEXT/KAHL]

  1. // Sample Dialog Plug In
  2. //
  3. // © 1996 Now Software, Inc
  4. // written by: hac
  5.  
  6. #include "Main.h"
  7. #include <Quickdraw.h>
  8.  
  9. #define kMyPlugInStrings        128
  10. #define    kMenuTextIndex            1
  11. #define kMyPlugInDialog            128
  12.  
  13. #define kOkay                    1
  14. #define kCancel                    2
  15.  
  16. pascal void main(PlugInInformation *plugInInformation)
  17. {
  18.     plugInInformation->version = kPlugInInformationVersionOne;
  19.     plugInInformation->plugInType = kDialogPlugIn;
  20.     plugInInformation->PrepareMenu = &PrepareMenu;
  21.     plugInInformation->HandleMenuItemSelected = &HandleMenuItemSelected;
  22. }
  23.  
  24. pascal void PrepareMenu(InstantAccessInformation *information, short asPreview)
  25. {
  26.     MenuItemInformation    menuItem;    
  27.  
  28.     // add a divider above
  29.     menuItem.version = kMenuItemInformationVersionOne;
  30.     menuItem.classification = kMiscellaneousClassification;
  31.     menuItem.type = kDividerMenuItemType;
  32.     menuItem.id = 1;
  33.     menuItem.enabled = true;
  34.     menuItem.style = 0;
  35.     menuItem.mark = 0;
  36.     menuItem.hasSubMenu = FALSE;
  37.     menuItem.subMenu = nil;
  38.     menuItem.refCon = 0;
  39.     menuItem.owningPlugInType = kDialogPlugIn;
  40.     
  41.     (*information->AddMenuItem)(&menuItem);
  42.  
  43.  
  44.  
  45.     BlockMove("\pSample Plug In Dialog", menuItem.text, kMenuItemTextSize);
  46.             
  47.     menuItem.type = kTextMenuItemType;
  48.     menuItem.id = 2;
  49.     menuItem.enabled = true;
  50.     
  51.     (*information->AddMenuItem)(&menuItem);
  52.  
  53.     BlockMove("\pSample Plug In Dialog", menuItem.text, kMenuItemTextSize);
  54.             
  55.     menuItem.type = kDividerMenuItemType;
  56.     menuItem.id = 3;
  57.     menuItem.enabled = true;
  58.     
  59.     (*information->AddMenuItem)(&menuItem);
  60.  
  61. }
  62.  
  63. pascal void CleanUpAfterMenuSelect(InstantAccessInformation *information, short asPreview)
  64. {
  65.     //hmmmm....
  66. }
  67.  
  68. pascal void HandleMenuItemSelected(InstantAccessInformation *information, MenuItemInformation *menuItem)
  69. {
  70.     GrafPtr        currPort                = nil;
  71.     DialogPtr    myPlugInDialog            = nil;
  72.     short        itemHit;
  73.     FSSpec        spec;
  74.     short        curResFile;
  75.     short        refNum                    = -1;
  76.     Boolean        finished                = FALSE;
  77.  
  78.     curResFile = CurResFile();
  79.  
  80.     (*information->GetPlugInFileSpec)(kDialogPlugIn, &spec);
  81.  
  82.     refNum = FSpOpenResFile(&spec, fsRdWrPerm);
  83.     if (refNum == -1) {
  84.         goto error;
  85.     }
  86.  
  87.     myPlugInDialog = GetNewDialog(kMyPlugInDialog, nil, (WindowPtr)-1);
  88.     
  89.     if (myPlugInDialog == nil) {
  90.         goto error;
  91.     }
  92.  
  93.     GetPort(&currPort);
  94.     SetPort(myPlugInDialog);
  95.  
  96.  
  97.     do {
  98.         ModalDialog(nil, &itemHit);
  99.  
  100.         switch (itemHit) {
  101.  
  102.             case kOkay:
  103.                 finished = TRUE;
  104.                 break;
  105.  
  106.             case kCancel:
  107.                 finished = TRUE;
  108.                 break;
  109.  
  110.             otherwise:;
  111.  
  112.         }
  113.                 
  114.     } while ( !finished);
  115.  
  116.     
  117.  
  118. error:
  119.     if (myPlugInDialog != nil) {
  120.         DisposDialog(myPlugInDialog);
  121.     }
  122.  
  123.     if (currPort != nil) {
  124.         SetPort(currPort);
  125.     }
  126.  
  127.     if (refNum != -1) {
  128.         CloseResFile(refNum);
  129.     }
  130.  
  131.     UseResFile(curResFile);
  132. }
  133.